﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

using KingRoad.EPM.PersonnelLogEntity.Model;
using Unis.Framework.Core.Utility;
using KingRoad.EPM.PersonnelLogDAL.PlmConstructionlogcivilService;


namespace KingRoad.EPM.PersonnelLogBLL.UIRules
{
    /// <summary> 
    /// 客户端业务处理类。 
    /// 文件生成时间 2017/1/12 13:57:53
    /// </summary> 
    public class PlmConstructionlogcivilUIRule
    {
        private readonly IPlmConstructionlogcivilService _plmConstructionlogcivilService;


        public PlmConstructionlogcivilUIRule() { }

        /// <summary> 
        /// construct function... 
        /// </summary> 
        public PlmConstructionlogcivilUIRule(IPlmConstructionlogcivilService plmConstructionlogcivilService)
        {
            _plmConstructionlogcivilService = plmConstructionlogcivilService;
        }

        /// <summary>
        /// 插入 人员日志管理—施工日志（土建）对象
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public bool InsertPlmConstructionlog(PlmConstructionlogcivilInfo entity)
        {
            var ret = _plmConstructionlogcivilService.InsertEntity(entity);
            return ret > 0;
        }

        /// <summary>
        /// 根据总监标段号查询
        /// </summary>
        /// <param name="directorSection"></param>
        /// <returns></returns>
        public List<PlmConstructionlogcivilInfo> GetInfoByDirectorSection(string directorSection)
        {
            var sqlStr = String.Format(" Clc_DirectorSection='{0}' ", directorSection);
            var ret = _plmConstructionlogcivilService.GetEntityList(sqlStr);
            return ret;
        }

        /// <summary>
        /// 根据总监办标号，和施工日期分组查询信息
        /// </summary>
        /// <param name="directorSection">总监办标号</param>
        /// <returns></returns>
        public List<PlmConstructionlogcivilInfo> GetInfoListGroupByDirectorSection(string directorSection)
        {
            var strWhere = " 1=1 ";
            if (!String.IsNullOrEmpty(directorSection))
            {
                strWhere = String.Format(" Clc_DirectorSection='{0}' ", directorSection);
            }
            var ret = _plmConstructionlogcivilService.GetInfoListGroupByDirectorSection(strWhere);
            return ret;
        }

        /// <summary>
        /// 总监办人员----根据总监办标号和施工日期查询
        /// </summary>
        /// <param name="directorSection"></param>
        /// <param name="constructionDate"></param>
        /// <returns></returns>
        public List<PlmConstructionlogcivilInfo> GetInfoListByCondition(string directorSection, string constructionDate)
        {
            return this.GetInfoListByCondition(directorSection, constructionDate, null, null);
        }

        /// <summary>
        /// 驻地办人员----根据总监办标号，施工日期，驻地办标号查询
        /// </summary>
        /// <param name="directorSection"></param>
        /// <param name="constructionDate"></param>
        /// <param name="stationSection"></param>
        /// <returns></returns>
        public List<PlmConstructionlogcivilInfo> GetInfoListByCondition(string directorSection, string constructionDate, string stationSection)
        {
            return this.GetInfoListByCondition(directorSection, constructionDate, stationSection, null);
        }

        /// <summary>
        /// 施工单位人员----根据总监办标号，施工日期，驻地办标号，施工单位ID查询
        /// </summary>
        /// <param name="directorSection"></param>
        /// <param name="constructionDate"></param>
        /// <param name="stationSection"></param>
        /// <param name="constructionId"></param>
        /// <returns></returns>
        public List<PlmConstructionlogcivilInfo> GetInfoListByCondition(string directorSection, string constructionDate,
                                                                        string stationSection, string constructionId)
        {
            var strWhere = String.Format(" Clc_DirectorSection='{0}' AND CONVERT(VARCHAR,Clc_ConstructionDate,120) LIKE '{1}%' ", directorSection, constructionDate);
            if (!String.IsNullOrEmpty(stationSection))
                strWhere += String.Format(" AND Clc_StationSection='{0}'", stationSection);
            if (!String.IsNullOrEmpty(constructionId))
                strWhere += String.Format(" AND Clc_ConstructionID='{0}'", constructionId);
            strWhere += " ORDER BY Clc_ConstructionSection ";
            var retList = _plmConstructionlogcivilService.GetEntityList(strWhere);

            return retList;
        }

        /// <summary>
        /// 总监办人员----根据总监办标号和施工日期查询
        /// </summary>
        /// <param name="directorSection"></param>
        /// <param name="constructionDate"></param>
        /// <returns></returns>
        public DataTable GetInfoListByConditionDT(string directorSection, string constructionDate)
        {
            return this.GetInfoListByConditionDT(directorSection, constructionDate, null, null);
        }

        /// <summary>
        /// 驻地办人员----根据总监办标号，施工日期，驻地办标号查询
        /// </summary>
        /// <param name="directorSection"></param>
        /// <param name="constructionDate"></param>
        /// <param name="stationSection"></param>
        /// <returns></returns>
        public DataTable GetInfoListByConditionDT(string directorSection, string constructionDate, string stationSection)
        {
            return this.GetInfoListByConditionDT(directorSection, constructionDate, stationSection, null);
        }
        /// <summary>
        /// 施工单位人员----根据总监办标号，施工日期，驻地办标号，施工单位ID查询
        /// </summary>
        /// <param name="directorSection"></param>
        /// <param name="constructionDate"></param>
        /// <param name="stationSection"></param>
        /// <param name="constructionId"></param>
        /// <returns></returns>
        public DataTable GetInfoListByConditionDT(string directorSection, string constructionDate,
            string stationSection, string constructionId)
        {
            var strWhere = String.Format(" Clc_DirectorSection='{0}' AND CONVERT(VARCHAR,Clc_ConstructionDate,120) LIKE '{1}%' ", directorSection, constructionDate);
            if (!String.IsNullOrEmpty(stationSection))
                strWhere += String.Format(" AND Clc_StationSection='{0}'", stationSection);
            if (!String.IsNullOrEmpty(constructionId))
                strWhere += String.Format(" AND Clc_ConstructionID='{0}'", constructionId);
            strWhere += " ORDER BY Clc_ConstructionSection ";
            var retList = _plmConstructionlogcivilService.GetInfoListByCondition(strWhere);

            return retList;
        }


        /// <summary>
        /// 更新总监办评述
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool UpdateDirectorCommentInfo(List<PlmConstructionlogcivilInfo> list)
        {
            var ret = _plmConstructionlogcivilService.UpdateDirectorCommentInfo(list);
            return ret;
        }

        /// <summary>
        /// 更新驻地办办评述
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool UpdateStationCommentInfo(List<PlmConstructionlogcivilInfo> list)
        {
            var ret = _plmConstructionlogcivilService.UpdateStationCommentInfo(list);
            return ret;
        }


        public bool InsterConstructionlogInfo(Dictionary<string, string> formValues)
        {
            var ret= _plmConstructionlogcivilService.InsterConstructionlogInfo(formValues);
            return ret;
        }

        public bool UpdateConstructionlogInfo(Dictionary<string, string> formValues)
        {
            var ret = _plmConstructionlogcivilService.UpdateConstructionlogInfo(formValues);
            return ret;
        }

        /// <summary>
        /// 根据条件查询施工日志土建信息
        /// </summary>
        /// <param name="numCurrentPage">当前页</param>
        /// <param name="numPerPage">每页数据大小</param>
        /// <param name="orderByField">排序字段名称</param>
        /// <param name="totalRecord">总数据量</param>
        /// <param name="sqlCondition">sql查询条件</param>
        /// <returns></returns>
        public List<PlmConstructionlogcivilInfo> GetAltPlmConstructionlogForPage(int numCurrentPage, int numPerPage, string orderByField, out int totalRecord, string sqlCondition)
        {
            var list = _plmConstructionlogcivilService.GetEntityListByContionRe(numCurrentPage, numPerPage, orderByField, out totalRecord, sqlCondition);
            return list;
        }


        public int DeleteObjById(string id) 
        {
           var ret=  _plmConstructionlogcivilService.DeleteEntityByStringID(id);
            return ret;
        }
        /// <summary>
        /// 判断是否存在AssisId
        /// </summary>
        /// <param name="assisId"></param>
        /// <returns></returns>
        public bool IsExitAssistId(int assisId)
        {
            var strSql = String.Format(" Assist_ID={0} ", assisId);
            var list = _plmConstructionlogcivilService.GetEntityList(strSql);
            return list.Any();
        }
    }
}
